package cn.com.blueInfo.bpm.common.controller;

import cn.com.blueInfo.core.manager.EncryptionKeyManager;
import cn.com.blueInfo.utils.result.ResultInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.security.PublicKey;
import java.util.Base64;

@Tag(name = "密钥管理控制器")
@RestController
@RequestMapping("/encryption")
public class EncryptionManagerController {

    @Autowired
    private EncryptionKeyManager encryptionKeyManager;

    @Operation(summary = "获取前端加密公钥")
    @GetMapping("/getHttpPublicKey")
    public ResultInfo<String> getHttpPublicKey() {
        PublicKey publicKey = encryptionKeyManager.getPublicKey_http();
        String publicKeyStr = Base64.getEncoder().encodeToString(publicKey.getEncoded());
        return ResultInfo.<String>builder().data(publicKeyStr).message("前端加密公钥获取成功").build();
    }

}
